package com.test.auth_db_auto.support.oauth2;

import com.test.auth_db_auto.response.HttpResponse;
import com.test.auth_db_auto.utils.HttpUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 处理权限相关异常
 * @ Author: .Mr
 * @ ClassName BootAccessDeniedHandler
 * @ Description TODO
 * @ date 2021/12/17 14:38
 * @ Version 1.0
 * 请求拒绝，没有权限
 */
@Component
public class BootAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
        System.out.println("没有权限");
        HttpUtils.writer(HttpResponse.baseResponse(HttpStatus.FORBIDDEN.value(),"没有权限"),response);
    }
}
